<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath }/js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<link id="easyuiTheme" rel="stylesheet" type="text/css"	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"	type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/outOfBounds.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/common.js" type="text/javascript"></script>

<!-- 导入ztree类库 -->
<link rel="stylesheet" href="${pageContext.request.contextPath }/js/ztree/zTreeStyle.css" type="text/css" />
<script	src="${pageContext.request.contextPath }/js/ztree/jquery.ztree.all-3.5.js" type="text/javascript"></script>	

</head>

<body>
	<table class="easyui-datagrid" id="roleList" title="角色列表" 
       data-options="singleSelect:false,collapsible:true,pagination:true,url:'${pageContext.request.contextPath}/admin/rolelist',method:'get',pageSize:30,toolbar:toolbar">
    <thead>
        <tr>
        	<th data-options="field:'ck',checkbox:true"></th>
        	<th data-options="field:'id',width:120,align:'center'">编号</th>
            <th data-options="field:'name',width:200,align:'center'">名称</th>
            <th data-options="field:'description',width:300,align:'center'">描述</th>
        </tr>
    </thead>
</table>
</body>
<div id="roleAddWindow" class="easyui-window" title="添加角色" data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/role_add'" style="width:1000px;height:500px;padding:10px;">
<div id="roleEditWindow" class="easyui-window" title="编辑角色" data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/role_edit'" style="width:1000px;height:500px;padding:10px;">
</div>
<script>
	//获取选中的ID值
    function getSelectionsIds(){
    	var articleList = $("#roleList");
    	var sels = articleList.datagrid("getSelections");
    	var ids = [];
    	for(var i in sels){
    		ids.push(sels[i].id);
    	}
    	ids = ids.join(",");
    	return ids;
    }
	
	//删除功能
	function doDelete(){
		//获取选中的id
		var ids = getSelectionsIds();
		
		$.messager.confirm('确认','确定删除ID为 '+ids+' 的角色吗？',function(r){
    	    if (r){
    	    	var params = {"ids":ids};
            	$.post("${pageContext.request.contextPath }/admin/roledelete",params, function(data){
        			if(data.status == 200){
        				$.messager.alert('提示',data.data,undefined,function(){
        					$("#roleList").datagrid("reload");
        				});
        			}
        		});
    	    }
    	});
		
	}
	
	//添加功能
	function doAdd(){
		//打开弹窗
		$("#roleAddWindow").window( ).window("open");
		
		
	}
	
	//编辑功能
	function doEdit(){
		var ids = getSelectionsIds();

    	if(ids.length == 0){
    		$.messager.alert('提示','必须选择一个角色才能编辑!');
    		return ;
    	}
    	if(ids.indexOf(',') > 0){
    		$.messager.alert('提示','只能选择一个角色!');
    		return ;
    	}
    	
    	$("#roleEditWindow").window({
    		onLoad :function(){
    			//回显基础数据
    			//获取选中行的数据
    			var data = $("#roleList").datagrid("getSelected");
    			//打印测试
    			//alert(data.name);
    			$("#roleEditForm").form("load",data);
    		}
    	}
   		).window("open");
    	
	}

    var toolbar = [{
        text:'添加角色',
        iconCls:'icon-add',
        handler:doAdd
    },{
        text:'编辑角色',
        iconCls:'icon-edit',
        handler: doEdit
    },{
        text:'删除角色',
        iconCls:'icon-cancel',
        handler: doDelete
    }];
    
</script>